package cn.com.czpb.client.custorm.swiperefreshhelper;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import cn.com.czpb.client.R;
import com.powyin.scroll.widget.SwipeController;

/**
 * Created by Administrator on 2017/9/1.
 */

public class SwipeRefreshHelper_index implements SwipeController{
    private Context mContent;
    public final AnimationDrawable animationDrawable;

    private View headView;

    private View overHead;
    private ProgressBar statusPre;

    private ImageView statusComplete;
    private TextView textInfo;

    private View footView;
    private TextView loadProgressBar;
    private TextView textLoad;
    public SwipeRefreshHelper_index(Context context) {
        this.mContent=context;
        LayoutInflater inflater=LayoutInflater.from(mContent);
        this.headView=inflater.inflate(R.layout.load_progress_index,null);
        statusComplete = headView.findViewById(R.id.loadingImageView);
        animationDrawable = (AnimationDrawable) statusComplete.getBackground();
        textInfo= headView.findViewById(R.id.text_info);
        textInfo = headView.findViewById(R.id.text_info);
        overHead=headView.findViewById(R.id.head);
        this.footView=inflater.inflate(R.layout.load_progress,null);


//        ImageView imageView = (ImageView) headView.findViewById(R.id.loadingImageView);
//        AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
//        animationDrawable.start();
    }
    public void setTitle(boolean set){
        if (set){
            textInfo.setText("下拉可以刷新");
            animationDrawable.stop();
        }
    }

    @Override
    public View getSwipeHead() {
        return headView;
    }

    @Override
    public View getSwipeFoot() {
        return footView;
    }

    @Override
    public int getOverScrollHei() {
        return overHead.getHeight();
    }

    @Override
    public void onSwipeStatue(SwipeStatus status, int visibleHei, int wholeHei) {
        switch (status) {
            case SWIPE_HEAD_OVER:

                statusComplete.setVisibility(View.VISIBLE);
                if(!textInfo.getText().toString().equals("下拉可以刷新")){
                    textInfo.setText("下拉可以刷新");
                }
//
                break;
//            case SWIPE_HEAD_TOAST:
////
//                statusComplete.setVisibility(View.INVISIBLE);
////
//                if(!textInfo.getText().toString().equals("上拉刷新")){
//                    textInfo.setText("上拉刷新");
//                }
//                break;
            case SWIPE_HEAD_LOADING:

                statusComplete.setVisibility(View.VISIBLE);
                if(!textInfo.getText().toString().equals("正在刷新数据中...")){
                    textInfo.setText("正在刷新数据中...");
                }
                break;
            case SWIPE_HEAD_COMPLETE_OK:

                statusComplete.setVisibility(View.VISIBLE);
                if(!textInfo.getText().toString().equals("下拉可以刷新")){
                    textInfo.setText("下拉可以刷新");
                }
                break;
//
//            case SWIPE_LOAD_LOADING:
//                loadProgressBar.setVisibility(View.VISIBLE);
//                textLoad.setVisibility(View.GONE);
//                break;
//            case SWIPE_LOAD_NO_MORE:
//                loadProgressBar.setVisibility(View.GONE);
//                textLoad.setVisibility(View.VISIBLE);
//                break;
        }
    }

}
